extends PanelContainer

signal move_click
signal wait_click
signal attack_click

onready var mask = get_parent().get_node("Mask")
onready var panel = get_parent().get_node("Panel")

func _on_MoveBtn_pressed() -> void:
	Game.game_state = Game.GAMESTATE.SELECTMOVEPATH
	emit_signal("move_click")
	ctrl_menu(false)

func _on_WaitBtn_pressed() -> void:
	Game.game_state = Game.GAMESTATE.IDLE
	emit_signal("wait_click")
	ctrl_menu(false)

func _on_AttackBtn_pressed() -> void:
	Game.game_state = Game.GAMESTATE.SELECTATTACKPATH
	emit_signal("attack_click")
	ctrl_menu(false)

func _on_AbilyBtn_pressed() -> void:
	panel.visible = true

func ctrl_menu(is_show:bool):
	if is_show :
		Game.game_state = Game.GAMESTATE.SHOWMENU	
	visible = is_show

func set_pos(pos:Vector2):
	ctrl_menu(true)
	rect_global_position = pos

func ctrl_move_btn(is_show:bool):
	get_node("VBoxContainer/MoveBtn").visible = is_show
	rect_size = Vector2(rect_size.x,50)

func check_area(pos:Vector2) -> bool:
	var x = rect_global_position.x
	var y = rect_global_position.y
	var w = rect_size.x
	var h = rect_size.y
	var flag = false
	var flag1 = pos.x > x and pos.x < x+w
	var flag2 = pos.y > y and pos.y < y+h
	
	if flag1 and flag2 and visible:
		flag = true
	
	return flag
